package com.lc.recovery.ui.activity.warehousemine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.recovery.R;
import com.lc.recovery.app.AppActivity;
import com.lc.recovery.http.request.StorageWorkerListApi;
import com.lc.recovery.http.response.StorageWorkerListBean;
import com.lc.recovery.other.IntentKey;
import com.lc.recovery.ui.activity.LoginActivity;
import com.lc.recovery.ui.activity.warehousehome.StorageAddListActivity;
import com.lc.recovery.util.CourseUtils;
import com.lc.recovery.util.SPUtil;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class StorageWorkerListActivity extends AppActivity {

    @BindView(R.id.rv_recoverymessage)
    RecyclerView rvRecoverymessage;
//    @BindView(R.id.layout_refresh)
//    TwinklingRefreshLayout layoutRefresh;

    private List<StorageWorkerListBean.DataBean> dataBeanList = new ArrayList<>();
    private int page = 1;

    private BaseQuickAdapter<StorageWorkerListBean.DataBean, BaseViewHolder> messageWarehousedapter;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_storageworkerlist;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        storage_totals(page);
        messageWarehousedapter = new BaseQuickAdapter<StorageWorkerListBean.DataBean, BaseViewHolder>(R.layout.item_storageworker, dataBeanList) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, StorageWorkerListBean.DataBean bean) {
                baseViewHolder.setText(R.id.tv_type, bean.getReal_name());
                baseViewHolder.setText(R.id.tv_weight,bean.getCreate_time());

            }
        };

        View emptyview1 = View.inflate(getContext(), R.layout.empty_emptylayout, null);
        messageWarehousedapter.setEmptyView(emptyview1);
        rvRecoverymessage.setAdapter(messageWarehousedapter);
        messageWarehousedapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                if (!CourseUtils.isNotNullOrEmpty(SPUtil.get(getContext(), IntentKey.USERID, ""))) {
                    startActivity(LoginActivity.class);
                    return;
                }
                startActivity(new Intent(getContext(), StorageAddListActivity.class).putExtra("id",dataBeanList.get(position).getWorker_id()+""));
            }
        });

//        layoutRefresh.setOnRefreshListener(new RefreshListenerAdapter() {
//            @Override
//            public void onRefresh(TwinklingRefreshLayout refreshLayout) {
//                super.onRefresh(refreshLayout);
//                page = 1;
//                storage_totals(page);
//
//
//                refreshLayout.finishRefreshing();
//
//            }
//
//            @Override
//            public void onLoadMore(TwinklingRefreshLayout refreshLayout) {
//                super.onLoadMore(refreshLayout);
////                refreshLayout.finishLoadmore();
////                if (!TextUtils.isEmpty(goods_classify_id)) {
//
//
//
//                refreshLayout.setEnableLoadmore(false);
//
//
////                }
//
////         }
//            }
//        });

    }



    private void storage_totals(int page) {
        EasyHttp.post(this)
                .api(new StorageWorkerListApi()).request(new HttpCallback<StorageWorkerListBean>(this) {

            @Override
            public void onSucceed(StorageWorkerListBean data) {
                if (data.getCode() == 200) {
                    dataBeanList.clear();
                    dataBeanList.addAll(data.getData());
                    messageWarehousedapter.setNewData(dataBeanList);
                    messageWarehousedapter.notifyDataSetChanged();

                }

            }

            @Override
            public void onFail(Exception e) {
                super.onFail(e);

            }
        });
    }
}
